@{
    ViewBag.Title = "权限管理";
}
@section head{
   <link href="@Url.Content("~/Content/Images/UploadIcons/icons.css")" rel="stylesheet" type="text/css" />
   <script type="text/javascript">
       var type;
       var code;

       $(document).ready(function () {
           loadData();
       });
       //加载权限数据
       function loadData() {
           type=$('#Type').combobox('getValue');
           code=$('#Code').val();
           if(code && code!=''){
               var url = serverUrl.list + '?' + 'usertype=' + type + '&usercode=' + code;
               $('#details').treegrid('options').url=url;
               $('#details').treegrid('reload');
           }
       }

       function selectCode(){
           if($('#Type').combobox('getValue')==1){
               dialogCode='Manager';
           }
           else{
               dialogCode='ManagerRole';
           }
            DataDialog.Show(dialogCode,false,true,undefined,function(value){
                $('#Code').val(value.result);
                loadData();
            });
       }

       function ajaxupdate(resourceCode, chk, field) {
           postModal('@Url.Action("UpdateProperty")', 
            {userType:type,userCode:code,resourceCode:resourceCode, field: field, value: chk.checked, rnd: Math.random() }
            ,function (r) {
               if (r.success == false) {
                   chk.checked=!chk.checked;
               }
           }, false);
       }

       function aformat(value, row, index) {
           var ret = null;
           if (value) {
               ret = hrefformat(value, value, row.text, true, row.iconCls);
           }
           return ret;
       }

       var menuType=@Html.Raw(new OA.Mvc3.Controllers.DictionaryController().GetChilds("ResourceType"));       
       function typeformat(value, row, index) {
          return dicformat(menuType,value);
       }

       function allowformatter(value, row, index) {
           return ajaxcheckbox(value, row, index, 'IsAllow');
       }
       function denyformatter(value, row, index) {
           return ajaxcheckbox(value, row, index, 'IsDeny');
       }
       function delegateformatter(value, row, index) {
           return ajaxcheckbox(value, row, index, 'IsDelegate');
       }
       function ajaxcheckbox(value, row, index, field) {
           return '<input type="checkbox" class="authoritycheckbox"  value="true"'
                  + (value == true ? 'checked="checked"' : '')
                  + ' onclick="ajaxupdate(\'' + row.id + '\',this,\'' + field + '\')"/>';
       }
   </script>
}
@section body{
<body>
<div class="easyui-layout" data-options="fit:true">
    <div region="north" border="false">
        <div class="navigation">
            <div class="left">
                @ViewBag.CurrentPath
            </div>
            @if(!string.IsNullOrEmpty(ViewBag.code)) {<a href="javascript:CloseMe();" class="back">后退</a>}
        </div>
        <div class="tools_box">
	        <div class="tools_bar">
            	对象类型： <select id="Type" name="Type" class="easyui-combobox txtSearchInput" data-options="panelHeight:'auto'" >
                          @Html.Raw(OA.UI.Controls.SelectByDictionary("RoleUserType", ViewBag.type, false))
                      </select>
                对象编号：<input type="text" id="Code" name="Code" readonly="readonly" class="txtSearchInput" value="@ViewBag.code" />
                <img class="triggerDataDialog" src="@Url.Content("~/Content/Images/Icons/search.png")" onclick="selectCode()" />
            </div>
            <div class="search_box">

		    </div>
        </div>
    </div> 
    <div region="center" border="false">
        <table class="easyui-treegrid" id="details" data-options="fit:true,rownumbers:true,singleSelect:false,
          pagination:false,border:true,idField:'id',treeField: 'text'">
           <thead data-options="frozen:true"> 
              <tr>
                   <th data-options="field:'id',hidden:true">资源编号</th>
                   <th data-options="field:'text',width:180">资源名称</th>
                   <th data-options="field:'Code',width:150">资源编号</th>
              </tr>
           </thead>
           <thead>  
               <tr>  
                   <th data-options="field:'resourceType',width:80,formatter:typeformat">类型</th>
                   <th data-options="field:'IsAllow',sortable:false,width:80,align:'center',formatter:allowformatter">允许</th>
                   <th data-options="field:'IsDeny',sortable:false,width:80,align:'center',formatter:denyformatter">拒绝</th>
                   <th data-options="field:'IsDelegate',sortable:false,width:80,align:'center',formatter:delegateformatter">允许授权</th>
               </tr>  
           </thead>  
        </table>
    </div>
</div>
</body>
}